<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Validate;
use app\common\model\Talk as TalkModel;

/**
 * 对话接口
 */
class Talk extends Api
{

    /**
     * 对话列表
     * @var array
     */
    protected $noNeedRight = '*';

    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new TalkModel();
    }
    /**
     * 查询对话表
     * @ApiTitle    (查询对话表)
     *  @ApiParams (name="limit", type="int", required=true, description="查询条数")
     *  @ApiMethod  (POST)
     *  @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     *  @ApiReturnParams   (name="msg", type="string", required=true, sample="查询成功")
     *  @ApiReturn   ({
          'code':'200',
          'msg':'查询成功',
          'time': "",
          'data': $row
        })
     */
    public function talkIndex()
    {
        $data = input('post.');
        $limit = $data['limit'] ? $data['limit'] : 3;
        if (!Validate::is($limit, 'number')) {
            $this->error('参数错误');
        }
        $row = $this->model->dataList('', 'id,content','RAND()',$limit);
        $this->success('查询成功', $row);
    }

}